<?php if( ($oNode) && ($iParentId) ): ?>
  <?php $aNodeChildrenList = $oNode->getChildren(); ?>
  <?php foreach($aNodeChildrenList as $oNodeChildren): ?>
    <?php $iNodeChildrenId = call_user_func(array($oNodeChildren, sfConfig::get('app_caPropelTreePlugin_sObjectIdMethod'))); ?>
    <li   class="doc" >
      <span id="node_<?php echo $iNodeChildrenId; ?>" class="action">
        <?php include_partial('caPropelTree/nodeName',array('oNode' => $oNodeChildren)); ?>
      </span>
      <?php include_partial('caPropelTree/nodeMenu',array('iNodeId' => $iNodeChildrenId, 'iParentId' => $iParentId)) ;?>

      <?php if($oNodeChildren->hasChildren() ): ?>
        <script type="text/javascript">
          $(document).ready(function(){
             //if node have children change class name to folder-close
             $("#node_<?php echo $iNodeChildrenId; ?>").parent().removeClass("doc").addClass("folder-close");
             //if node was first write, add class 'not-load'
             $("#node_children_<?php echo $iNodeChildrenId; ?>").addClass("not-load");
          });
        </script>
      <?php endif; ?>

      <script type="text/javascript">
        $(document).ready(function(){
          $("#node_<?php echo $iNodeChildrenId; ?>").click(function(){
            elem = $("#node_<?php echo $iNodeChildrenId; ?>").parent();
            if (elem.hasClass("folder-close")) {
              $("#node_children_<?php echo $iNodeChildrenId; ?> ").parent(".folder-close").removeClass("folder-close").addClass("folder-open");
              //folder close
              if( $("#node_children_<?php echo $iNodeChildrenId; ?> ").hasClass("not-load") )
              {
                $("#node_children_<?php echo $iNodeChildrenId; ?> ").load("<?php echo url_for('ca_get_tree',array('node_id' =>  $iNodeChildrenId )); ?>");
                $("#node_children_<?php echo $iNodeChildrenId; ?>").removeClass("not-load");
              }
              else
              {
                $("#node_children_<?php echo $iNodeChildrenId; ?> ").show();
              }
            }
            else
            {
              //folder open
              $("#node_children_<?php echo $iNodeChildrenId; ?> ").parent(".folder-open").removeClass("folder-open").addClass("folder-close");
              $("#node_children_<?php echo $iNodeChildrenId; ?> ").hide();
            }
          });
        });
      </script>
        <ul id="node_children_<?php echo $iNodeChildrenId; ?>"></ul>
     </li>
   <?php endforeach; ?>
<?php endif; ?>
